﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Common.Servers
{
    public class OrderServers
    {
        private readonly IRepository<dinner_order> dinner_orderRepository;

        public OrderServers()
        {
            dinner_orderRepository = new DapperRepository<dinner_order>();

        }

        public List<dinner_order> GetData()
        {
            var datas = dinner_orderRepository.GetAllEnumerable();

            return datas.ToList();
        }

        public dinner_order GetModelById(string id)
        {
            return dinner_orderRepository.GetById(id);
        }


        internal void Add(dinner_order model)
        {
            dinner_orderRepository.Insert(model);
        }

        internal void Update(dinner_order model)
        {
            dinner_orderRepository.Update(model);
        }

        internal void Del(string id)
        {
            dinner_orderRepository.DeleteByIds(id);
        }


        internal List<SelectListItem> GetFY_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = dinner_orderRepository.SqlWithParamsDynamic("select DEPT_ID Value,DEPT_NAME Text from [dbo].[department]");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetWHICH_MEAL()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            tables.Add(new SelectListItem { Value = "B", Text = "早餐" });
            tables.Add(new SelectListItem { Value = "L", Text = "中餐" });
            tables.Add(new SelectListItem { Value = "D", Text = "晚餐" });

            return tables;
        }



        internal List<SelectListItem> GetMENU_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = dinner_orderRepository.SqlWithParamsDynamic("select ID Value, NAME Text from [dbo].[dinner_cookbook]");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


    }
}